
const app = getApp();
Component({
  options: {
    addGlobalClass: true,
  },
  data: {
    name: '首页用户名',
    projectList: [],
    visitTotal: 0,
    starCount: 0,
    forksCount: 0,
    DotStyle: true,
    cardCur: 0,
    activeNames: [],
  },
  properties: {
    userinfo: String
  },
  attached() {
    let that = this;
    console.log("app", app)
    console.log("that", that.coutNum)
    wx.showLoading({
      title: '数据加载中',
      mask: true,
    })
    this.getTaskList();
    
    wx.hideLoading()
    wx.getUserInfo({
      success: function (res) {
        that.setData({
          name: res.userInfo.nickName
        })
      }
    })
  },
  methods: {
    onChange(event) {
      this.setData({
        activeNames: event.detail,
      });
    },
    onOpenCollpase(e){
      console.log(e);
    },
    getTaskList(){
      app.AjaxPost({
        p0: {
          appName: "s6-service",
          methodName: "getProjectList",
          params: {},
          serviceName: "taskService"
        },
        servicename: "customService"
      }, (res)=>{
        console.log("数据返回：", res)
        if(res.status === "success"){
          let _this = this;
          /**
           * 数据动画效果
          */
          let taskTotal = 0;
          let todayTotal = 0;
          res.data.projectList.forEach(element => {
            taskTotal += element.mytask;
            todayTotal += element.todayneed;
            element.text = element.projectName;
            element.value = element.id;
            element.name = element.projectName;
          });
          _this.setData({
            projectList: res.data.projectList || []
          });

          let i = 0;
          var numDH = () => {
            if (i < 50) {
              setTimeout(() => {
                _this.setData({ starCount: i, forksCount: i, visitTotal: i})
                i++
                numDH();
              }, 50)
            } else {
              _this.setData({
                visitTotal: _this.coutNum(res.data.projectList.length),
                starCount: _this.coutNum(taskTotal),
                forksCount: _this.coutNum(todayTotal)
              })
            }
          }

          numDH();
        }
      });
    },
    cardSwiper(e) {
      this.setData({
        cardCur: e.detail.current
      })
    },
    coutNum(e) {
      var a = 100000000;
      if (e > a) {
        e = (e / a * 10000).toFixed(1) + '万'
      }
      return e
    },
    CopyLink(e) {
      wx.setClipboardData({
        data: e.currentTarget.dataset.link,
        success: res => {
          wx.showToast({
            title: '已复制',
            duration: 1000,
          })
        }
      })
    },
    // onOpen(event) {
    //   const { position, name } = event.detail;
    //   switch (position) {
    //     case 'left':
    //       Notify({
    //         type: 'primary',
    //         message: `${name}${position}部分展示open事件被触发`,
    //       });
    //       break;
    //     case 'right':
    //       Notify({
    //         type: 'primary',
    //         message: `${name}${position}部分展示open事件被触发`,
    //       });
    //       break;
    //   }
    // },
    gologin(){
      app.gotoLogin();
    },
    showModal(e) {
      this.setData({
        modalName: e.currentTarget.dataset.target
      })
    },
    hideModal(e) {
      this.setData({
        modalName: null
      })
    },
    showQrcode() {
      wx.previewImage({
        urls: ['https://image.weilanwl.com/color2.0/zanCode.jpg'],
        current: 'https://image.weilanwl.com/color2.0/zanCode.jpg' // 当前显示图片的http链接      
      })
    }
  }
})